<template>
  <div >
    <nav-title :title="title">
      <slot name="back"><img src="../../assets/箭头.png" alt="" class="slot-img"></slot>
    </nav-title>
    <div>
    <van-list  v-model="loading" :finished="finished" @load="updata"  finished-text="没有更多了"  >
      <div class="movie">            
        <movie-list v-for="item of movies" :list="item" :key="item.id"></movie-list>
      </div>
    </van-list>
    </div>
  </div>
</template>
<script>
import axios from "axios-jsonp-pro";
import NavTitle from "../../components/NavTitle";
import MovieList from "../../components/List";
export default {
  name: "Movie",
  components: {
    MovieList,
    NavTitle
  },
  data() {
    return {
      movies: [],
      title: "",
      loading: false,
      finished: false,
    };
  },
  mounted() {},
  methods: {
    updata() {
      console.log(1)
      // 异步更新数据等数据加载完再更新
      setTimeout(() => {
        var length = this.movies.length;        
        var type = this.$route.params.type;
        var url = `http://douban.uieee.com/v2/movie/${type}?start=${length}&count=20`;
        axios.jsonp(url).then(res => {
          this.title = res.title,
          this.movies = this.movies.concat(res.subjects)
          this.loading = false;
          // 数据全部加载完成
          if (this.movies.length >= res.total) {
            this.finished = true;
          }
        });
      }, 500);
    }
  }
};
</script>
<style lang="scss" scoped>
.movie {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 20px;
  background: #fff;
  margin-top: 90px;
}
.slot-img {
  width: 40px;
  height: 40px;
  position: absolute;
  top: 20px;
  left: 20px;
}
</style>
